package ray.mgocc.swing;

import ray.App;
import javax.swing.*;
import java.awt.Container;
import java.awt.Color;
import java.awt.event.ActionEvent;

public class CommunityClient{
    App app = new App();

    public JMenuBar getMenu(){
        JMenuBar bar = new JMenuBar();
        JMenu app = new JMenu("app");
        app.add(new JMenuItem("close"));
        bar.add(app);
        JMenu net = new JMenu("net");
        net.add(new JMenuItem(new LoginAction()));
        net.add(new JMenuItem("logout"));
        net.add(new JMenuItem("update"));
        net.add(new JMenuItem("select"));
        bar.add(net);
        JMenu file = new JMenu("file");
        file.add(new JMenuItem("open"));
        bar.add(file);
        JMenu view = new JMenu("view");
        view.add(new JMenuItem("score"));
        view.add(new JMenuItem("title"));
        bar.add(view);
        return bar;
    }
    public Container getContainer(){
        JPanel panel = new JPanel();
        panel.setBackground(Color.WHITE);
        return panel;
    }
    public void login(){
//         JDialog dialog = new JDialog();
//         JPanel panel = new JPanel();
//         panel.add(new JPasswordField());
//         panel.add(new JTextField());
//         dialog.add(panel);
//         JOptionPane.showInputDialog(panel,"message");
        showLoginDialog();
    }
    public void showLoginDialog(){
        JDialog dialog = new JDialog();
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        panel.add(new JPasswordField());
        panel.add(new JTextField());
        dialog.add(panel);
        dialog.show();
//         frame.add(panel);
//         frame.show();
    }
    class LoginAction extends AbstractAction{
        public LoginAction(){
            setup();
        }
        public String getName(){
            String name = getClass().getName();
            int start = getClass().getPackage().getName().length()+1;
            int end = name.length()-"Action".length();
            name = name.substring(start,end);
            return name;
        }
        public String getDescription(){
            return getName();
        }
        public int getKey(){return 0;}
        public void setup(){
            String name = getName();
            int key = getKey();
            String desc = getDescription();
            putValue(NAME,name);
            putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke
                     (key, ActionEvent.ALT_MASK));
            putValue(MNEMONIC_KEY,new Integer(key));
            putValue(ACTION_COMMAND_KEY,name);
            putValue(LONG_DESCRIPTION,desc);
            putValue(SHORT_DESCRIPTION,desc);
            //putValue(SMALL_ICON,null);
            //putValue(JComponent.TOOL_TIP_TEXT_KEY,desc);
        }
        public void actionPerformed(ActionEvent e){
            doit();
        }
        public void doit(){
            login();
        }
    }
}

